package com.cn.web.global.controller;

import com.cn.global.GlobalParamtersUtil;
import com.cn.global.GlobalparamtersExt;
import com.cn.msg.ResultMsg;
import com.cn.util.BaseController;
import com.cn.util.JsonUtil;
import com.cn.web.global.service.GlobalParamtersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * description: GlobalParamtersController <br>
 * date: 22.5.22 8:40 <br>
 * author: cn_yaojin <br>
 * version: 1.0 <br>
 */
@RestController
@RequestMapping(value = "admin/global")
@Api(tags = "全局参数设置")
public class GlobalParamtersController extends BaseController {


    @Autowired
    private GlobalParamtersService globalParamtersService;

    @ApiOperation(value = "编辑")
    @PostMapping(value = "edit")
    public ResultMsg edit(
            @RequestBody GlobalparamtersExt globalparamtersExt
    ) {
        GlobalParamtersUtil.add(globalparamtersExt);
        this.globalParamtersService.add(JsonUtil.toString(globalparamtersExt));
         return ResultMsg.builder();
    }

    @ApiOperation(value = "查看")
    @GetMapping(value = "find")
    public ResultMsg<GlobalparamtersExt> find() {
        var data = GlobalParamtersUtil.get();
        if (data == null) {
            data = this.globalParamtersService.find();
        }
        return ResultMsg.builder().setData(data);
    }

}
